package org.leetcode.easy.leetcode226;

import org.leetcode.TreeNode;

public class Solution
{

    public TreeNode invertTree2(TreeNode root) {
        if (root==null){
            return null;
        }

        TreeNode temp = root.left;
        root.left = root.right;

        root.right= temp;

        invertTree2(root.left);
        invertTree2(root.right);

        return root;

    }

    public TreeNode invertTree(TreeNode root) {

        if (root!=null)
        {
            TreeNode temp =null;
            temp = root.left;
            root.left = root.right;
            root.right=temp;

            invertTree(root.left);

            invertTree(root.right);
        }


        return root;

    }

}
